﻿CREATE TABLE [dbo].[RequestItems] (
    [Id]               UNIQUEIDENTIFIER DEFAULT (newid()) NOT NULL,
    [Address]          NVARCHAR (200)   NULL,
    [Geoposition]      NVARCHAR (40)    NULL,
    [Description]      NVARCHAR (255)   NOT NULL,
    [CreatedBy]        UNIQUEIDENTIFIER NOT NULL,
    [CreationDate]     DATETIME         NOT NULL,
    [Status]           INT              NOT NULL,
    [UpdateDate]       DATETIME         NULL,
    [UpdatedBy]        UNIQUEIDENTIFIER NULL,
    [RequestId]        UNIQUEIDENTIFIER NOT NULL,
    [Photo]            NVARCHAR (MAX)   NULL,
    [UserTypedAddress] NVARCHAR (200)   NULL,
    [CreatedByApp]     UNIQUEIDENTIFIER NULL,
    [StatusInfo]       NVARCHAR (500)   NULL,
    [Number]           NVARCHAR (24)    NULL,
    PRIMARY KEY CLUSTERED ([Id] ASC),
    FOREIGN KEY ([CreatedBy]) REFERENCES [dbo].[Users] ([Id]),
    FOREIGN KEY ([CreatedByApp]) REFERENCES [dbo].[Apps] ([Id]),
    CONSTRAINT [FK_RequestItems_0] FOREIGN KEY ([UpdatedBy]) REFERENCES [dbo].[UsersAuthentication] ([Id]),
    CONSTRAINT [FK_RequestItems_1] FOREIGN KEY ([RequestId]) REFERENCES [dbo].[Requests] ([Id])
);


GO
CREATE NONCLUSTERED INDEX [IX_CreatedBy]
    ON [dbo].[RequestItems]([CreatedBy] ASC);


GO
CREATE NONCLUSTERED INDEX [IX_RequestId]
    ON [dbo].[RequestItems]([RequestId] ASC);


GO
CREATE UNIQUE NONCLUSTERED INDEX [IX_Number]
    ON [dbo].[RequestItems]([Number] ASC);

